package work.model.com.mymvvm;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import work.model.com.mymvvm.databinding.ItemBinding;

/**
 * Description：
 * Created by cczhr on 2018/1/30.
 * email:cczhr1@163.com
 */

public class MainAdapter extends RecyclerView.Adapter<MainAdapter.MyHolder> {
    private List<UserBean> mUserBeanList;

    public MainAdapter(List<UserBean> mUserBeanList) {
        this.mUserBeanList = mUserBeanList;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        ItemBinding binding= DataBindingUtil.inflate(inflater,R.layout.item,parent,false);


        return new MyHolder(binding);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        holder.mItemBinding.setUser(mUserBeanList.get(position));

    }

    @Override
    public int getItemCount() {
        return mUserBeanList.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        private ItemBinding mItemBinding;

        public MyHolder(ItemBinding itemBinding) {
            super(itemBinding.getRoot());
            this.mItemBinding=itemBinding;
        }
    }
}
